package ${bag}.controller;

import ${bag}.domain.${name};
import ${bag}.query.${name}Query;
import ${bag}.service.I${name}Service;
import ${bag}.service.I${name}Service;
import ${bag}.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("${lname}")
public class ${name}Controller {
    @Autowired
    private I${name}Service ${lname}Service;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")${name}Query qo){
    // page
    Page<${name}> list = ${lname}Service.query(qo);

    model.addAttribute("page",list);
    return "${lname}/list";
    }

    @RequestMapping("/input")
    public String input(Model model,String id){
    if(StringUtils.hasLength(id)){
    // ${lname}
    ${name} ${lname} = ${lname}Service.get(id);
    model.addAttribute("${lname}",${lname});
    }
    return "${lname}/input";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(${name} ${lname}){
    ${lname}Service.saveOrUpdate(${lname});
    return JsonResult.success();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){
    ${lname}Service.delete(id);
    return JsonResult.success();
    }

}
